import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "ReadCookie", value = "/ReadCookie")
public class ReadCookie extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        PrintWriter out = response.getWriter();
        Cookie[] cookies = request.getCookies();
        if(cookies==null){
            out.print("you don't register");
        }
        else{
            Cookie cookie;
            for(int i=0;i<cookies.length;i++){
                cookie=cookies[i];
//                out.println("nihaohao");
                out.println("\nthe cookie name  is :"+cookie.getName());
                out.println("\nthe cookie value is :"+cookie.getValue());
            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }
}
